#ifndef __SLOTHTTPD_REF_COUNTED_HPP__
#define __SLOTHTTPD_REF_COUNTED_HPP__

#include <slothttpd/types.hpp>

#include <boost/intrusive_ptr.hpp>
#include <boost/noncopyable.hpp>

namespace slothttpd {

class ref_counted;
typedef boost::intrusive_ptr<ref_counted> ref_counted_ptr;

/**
 * @brief The ref_counted class
 * instances should be created in connections pool
 */
class ref_counted :
        public boost::noncopyable
{
    friend void intrusive_ptr_add_ref(ref_counted *r) noexcept;
    friend void intrusive_ptr_release(ref_counted *r) noexcept;
    
public:
    ref_counted();
    ref_counted(connection_ptr conn);
    
    virtual ~ref_counted();
    
protected:
    connection_ptr c;
    
private:
    unsigned ref_count_;
};

}

#endif
